package com.xiaotu.spider.tianya.pipeline;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.StarTianYaModel;
import com.xiaotu.common.model.TVTianYaModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 WeiboPipeline
 * @日期 2017年2月10日
 * @作者 高海军
 * @功能 天涯数据pipeline
 */
@Component("TianYaPipeline")
public class TianYaPipeline extends APipeline
{
	@Override
	protected void doProcess(ResultItems resultItems, Task task)
	{
		TVTianYaModel tvTianYaModel = resultItems
				.get(TVTianYaModel.class.getSimpleName());// 作品的天涯帖子
		if (tvTianYaModel != null)
		{
			String key = DataRedisKeyUtils
					.getKey(Constants.DataRedisKey.TV_Tianya_YYYYMMDD);
			cacheHandler.hSet(key,
					DataRedisKeyUtils.getTVTianYaKey(tvTianYaModel),
					tvTianYaModel);
			cacheHandler.setCacheTimeout(key);
		}
		
		StarTianYaModel starTianYaModel = resultItems
				.get(StarTianYaModel.class.getSimpleName());// 艺人的天涯帖子
		if (starTianYaModel != null)
		{
			String key = DataRedisKeyUtils
					.getKey(Constants.DataRedisKey.Star_Tianya_YYYYMMDD);
			cacheHandler.hSet(key,
					DataRedisKeyUtils.getStarTianYaKey(starTianYaModel),
					starTianYaModel);
			cacheHandler.setCacheTimeout(key);
		}
	}
}